package com.asset.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.asset.common.annotation.Log;
import com.asset.common.core.controller.BaseController;
import com.asset.common.core.domain.R;
import com.asset.common.enums.BusinessType;
import com.asset.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.asset.manage.domain.Region;
import com.asset.manage.service.IRegionService;


/**
 * 区域管理Controller
 *
 * @author mobin
 * @date 2024-08-24
 */
@Api(tags = "区域管理")
@RestController
@RequestMapping("/manage/region")
public class RegionController extends BaseController {
    @Autowired
    private IRegionService regionService;

    /**
     * 查询区域管理列表
     */
    @ApiOperation("查询区域管理列表")
    @PreAuthorize("@ss.hasPermi('manage:region:list')")
    @GetMapping("/list")
    public R<List<Region>> list(Region region) {
        List<Region> list = regionService.selectRegionList(region);
        return R.ok(list);
    }

    /**
     * 导出区域管理列表
     */
    @ApiOperation("导出区域管理列表")
    @PreAuthorize("@ss.hasPermi('manage:region:export')")
    @Log(title = "区域管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Region region) {
        List<Region> list = regionService.selectRegionList(region);
        ExcelUtil<Region> util = new ExcelUtil<Region>(Region.class);
        util.exportExcel(response, list, "区域管理数据");
    }

    /**
     * 获取区域管理详细信息
     */
    @ApiOperation("获取区域管理详细信息")
    @PreAuthorize("@ss.hasPermi('manage:region:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Integer id) {
        return R.ok(regionService.selectRegionById(id));
    }

    /**
     * 新增区域管理
     */
    @ApiOperation("新增区域管理")
    @PreAuthorize("@ss.hasPermi('manage:region:add')")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody Region region) {
        return R.ok(regionService.insertRegion(region));
    }

    /**
     * 修改区域管理
     */
    @ApiOperation("修改区域管理")
    @PreAuthorize("@ss.hasPermi('manage:region:edit')")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody Region region) {
        return R.ok(regionService.updateRegion(region));
    }

    /**
     * 删除区域管理
     */
    @ApiOperation("删除区域管理")
    @PreAuthorize("@ss.hasPermi('manage:region:remove')")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Integer[] ids) {
        return R.ok(regionService.deleteRegionByIds(ids));
    }
}
